﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Data;
using System.Windows.Markup;

namespace SmartRoomFinder.Helpers
{
    public class ObjectToBooleanConverters:MarkupExtension,IValueConverter
    {
        #region Converter
        private ObjectToBooleanConverters converter;
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (parameter != null)
            {
                if (value != null && parameter.ToString() == "Collapsed")
                {
                    return Visibility.Visible;
                }
                if (value == null && parameter.ToString() == "Collapsed")
                {
                    return Visibility.Collapsed;
                }
            }
            if (value == null)
            {
                return false;
            }
           
            return true;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return Binding.DoNothing;
        }

        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            return converter ?? (converter = new ObjectToBooleanConverters());
        }
        #endregion
    }
}
